package com.itshizhan.livedatademo

import android.util.Log
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel

class MainViewModel : ViewModel() {

    private var result: MutableLiveData<Int> = MutableLiveData()

    // 设置初始值
    init {
       // result.value = 0
    }

    fun add(number1: Int,number2:Int) {
       result.value = number1 + number2
    }

    fun getResult(): MutableLiveData<Int> {
        Log.d("itshizhan",result.value.toString())
        if (result.value==null){
            result.value = 0
        }
        return result
    }
}